﻿using FHJFPro.Base;
using FHJFPro.Const;
using FHJFPro.UserInfos;
using FHJFPro.UserInfos.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;

namespace FHJFPro.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>

    [ApiController]
    [Route("api/[controller]")]
    [ApiExplorerSettings(GroupName = GroupingAPI.GroupName_v1)]
    [Authorize]
    public class UserInfoController : AbpController
    {

        private readonly IUserInfoService _userInfoService;
        public UserInfoController(IUserInfoService userInfoService)
        {
            _userInfoService = userInfoService;
        }
        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CreateUserInfo")]
        public async Task<ResponseResult<UserInfoDto>> CreateUserInfo([FromBody] CreateUserInfoDto input)
        {
            return await _userInfoService.CreateAsync(input);
        }

        /// <summary>
        /// 批量新增用户
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("CreateManyUserInfo")]
        public async Task<ResponseResult<IEnumerable<UserInfoDto>>> CreateManyUserInfo([FromBody] IEnumerable<CreateUserInfoDto> input)
        {
            return await _userInfoService.CreateManyAsync(input);
        }

        /// <summary>
        /// 查询用户
        /// </summary>
        /// <param name="id">用户标识</param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetUserInfo")]
        public async Task<ResponseResult<UserInfoDto>> GetUserInfo([FromQuery] Guid id)
        {
            return await _userInfoService.GetAsync(id);
        }
        /// <summary>
        /// 根据用户名查询用户
        /// </summary>
        /// <param name="input">用户名</param>
        /// <returns></returns>
        [HttpGet]
        [Route("FindByName")]
        public async Task<ResponseResult<UserInfoDto>> FindByName([FromQuery]string input)
        {
            return await _userInfoService.FindByNameAsync(input);
        }
        /// <summary>
        /// 查找所有用户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [Route("GetAllUserInfo")]
        public async Task<ResponseResult<IEnumerable<UserInfoDto>>> GetAllUserInfo()
        {
            return await _userInfoService.GetAllAsync();
        }
        /// <summary>
        /// 用户分页列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("GetPageList")]
        public async Task<ResponseResult<List<UserInfoDto>>> GetPageList([FromQuery]GetUserInfoListDto input)
        {
            return await _userInfoService.GetPageListAsync(input);
        }

    }
}
